package NewCoder;

public class BM84 {
    public String longestCommonPrefix (String[] strs) {
        // write code here
        if(strs.length==0 || strs==null) return "";
        String s1=strs[0];
        for(int i=0;i<strs.length-1;i++){
            s1=getCommon(s1,strs[i+1]);
            if(s1.length()==0){
                return "";
            }
        }
        return s1;
    }
    private String getCommon(String s1,String s2){
        int len=Math.min(s1.length(),s2.length());
        int flag=0;
        while(flag<len && s1.charAt(flag)==s2.charAt(flag)){
            flag++;
        }
        return s1.substring(0,flag);

    }
}
